package com.dime.basic.service.impl;

import java.util.List;

import com.dime.basic.api.domain.DimeBasecomb;
import com.dime.basic.api.domain.DimeBasegroup;
import com.dime.basic.api.domain.DimeBasehealthadvice;
import com.dime.basic.mapper.DimeBasecombMapper;
import com.dime.basic.mapper.DimeBasehealthadviceMapper;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.uuid.IdUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.dime.basic.mapper.DimeBasegroupMapper;

import com.dime.basic.service.IDimeBasegroupService;

/**
 * 科室管理Service业务层处理
 *
 * @author Tiny
 * @date 2023-09-12
 */
@Service
public class DimeBasegroupServiceImpl implements IDimeBasegroupService
{
    @Autowired
    private DimeBasegroupMapper dimeBasegroupMapper;

    @Autowired
    private DimeBasecombMapper dimeBasecombMapper;

    @Autowired
    private DimeBasehealthadviceMapper dimeBasehealthadviceMapper;

    /**
     * 查询科室管理
     *
     * @param id 科室管理主键
     * @return 科室管理
     */
    @Override
    public DimeBasegroup selectDimeBasegroupById(String id)
    {
        return dimeBasegroupMapper.selectDimeBasegroupById(id);
    }

    /**
     * 查询科室管理列表
     *
     * @param dimeBasegroup 科室管理
     * @return 科室管理
     */
    @Override
    public List<DimeBasegroup> selectDimeBasegroupList(DimeBasegroup dimeBasegroup)
    {
        return dimeBasegroupMapper.selectDimeBasegroupList(dimeBasegroup);
    }

    /**
     * 新增科室管理
     *
     * @param dimeBasegroup 科室管理
     * @return 结果
     */
    @Override
    public int insertDimeBasegroup(DimeBasegroup dimeBasegroup)
    {
        dimeBasegroup.setId(IdUtils.fastUUID());
        dimeBasegroup.setCreateTime(DateUtils.getNowDate());
        dimeBasegroup.setCreateBy(SecurityUtils.getUsername());
        return dimeBasegroupMapper.insertDimeBasegroup(dimeBasegroup);
    }

    /**
     * 修改科室管理
     *
     * @param dimeBasegroup 科室管理
     * @return 结果
     */
    @Override
    public int updateDimeBasegroup(DimeBasegroup dimeBasegroup)
    {
        dimeBasegroup.setUpdateTime(DateUtils.getNowDate());
        dimeBasegroup.setUpdateBy(SecurityUtils.getUsername());

        DimeBasecomb dimeBasecomb = new DimeBasecomb();
        dimeBasecomb.setDimeGroupsid(dimeBasegroup.getId());
        dimeBasecomb.setGroupName(dimeBasegroup.getGroupName());
        dimeBasecombMapper.updateDimeBasecombByGroupId(dimeBasecomb);

        DimeBasehealthadvice dimeBasehealthadvice = new DimeBasehealthadvice();
        dimeBasehealthadvice.setGroupid(dimeBasegroup.getId());
        dimeBasehealthadvice.setGroupname(dimeBasegroup.getGroupName());
        dimeBasehealthadviceMapper.updateDimeBasehealthadviceByGroupId(dimeBasehealthadvice);

        return dimeBasegroupMapper.updateDimeBasegroup(dimeBasegroup);
    }

    /**
     * 批量删除科室管理
     *
     * @param ids 需要删除的科室管理主键
     * @return 结果
     */
    @Override
    public int deleteDimeBasegroupByIds(String[] ids)
    {
        return dimeBasegroupMapper.deleteDimeBasegroupByIds(ids);
    }

    /**
     * 删除科室管理信息
     *
     * @param id 科室管理主键
     * @return 结果
     */
    @Override
    public int deleteDimeBasegroupById(String id)
    {
        return dimeBasegroupMapper.deleteDimeBasegroupById(id);
    }

    @Override
    public List<DimeBasegroup> selectDimeBasegroupByIds(String[] ids)
    {
        return dimeBasegroupMapper.selectDimeBasegroupByIds(ids);
    }

    @Override
    public List<DimeBasegroup> selectDimeBasegroupByUserId(String userId)
    {
        return dimeBasegroupMapper.selectDimeBasegroupByUserId(userId);
    }
}
